/**
 *	Bigtable Constraints Parser
 */
grammar Stratus;

tokens {
	LT = '<';
	LTE = '<=';
	EQUAL1 = '==';
	EQUAL2 = ':';
	GTE = '>=';
	GT = '>';
	ASC = '+';
	DESC = '-';
	TRUE = 'true';
	FALSE = 'false';
}

@header {
	package com.inexas.cu.stratus;
}

@members {
	public String identifier, operator, literal;
	public char direction;
}

@lexer::header {
	package com.inexas.cu.stratus;
}

parse
	:	constraint EOF
	;

constraint
	:	i=Identifier direction? {
			identifier = $i.getText();
		}
	|	i=Identifier operator literal {
			identifier = $i.getText();
		}
	;

direction 
	:	d=( ASC | DESC ) {
			direction = d.getText().charAt(0);
		}
	;

operator
	:	c=(LT|LTE|EQUAL1|EQUAL2|GTE|GT) {
			operator = c.getText();
		}
	;
	
literal
	:	l=( String | Number | TRUE | FALSE ) {
			literal = l.getText();
		}
	;

// L e x e r


Identifier 
    :   JavaLetter (JavaLetter|Digit)*
    ;

Number
	:	(Digit | '.' | '-') (Digit |  'A'..'Z' | 'a'..'z' )*
	;

fragment
JavaLetter
    :  ( 'A'..'Z' | 'a'..'z' | '_' )
    ;

fragment
Digit
    :  '0'..'9'
	;

String
	:	'"' ( ~( '"' | '\\' ) | EscapeSequence )* '"'
	|	'\'' ( ~( '\'' | '\\' ) | EscapeSequence )* '\''
	;

fragment
EscapeSequence
	:	'\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
	|	UnicodeEscape
	|	OctalEscape
	;

fragment
UnicodeEscape
	:	'\\' 'u' HexDigit HexDigit HexDigit HexDigit
	;
	
fragment
OctalEscape
	:	'\\' ('0'..'3') ('0'..'7') ('0'..'7')
	|	'\\' ('0'..'7') ('0'..'7')
	|	'\\' ('0'..'7')
	;

fragment
HexDigit
	:	('0'..'9'|'a'..'f'|'A'..'F')
	;

WS
	:	(' ' | '\t' | '\n' | '\r')+ { $channel=HIDDEN; }
	;
	
